home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / add_part.c next >
Encoding:
C/C++ Source or Header  |  2004-01-09  |  4.1 KB  |  137 lines

  1. /*
  2.  
  3.     File: add_part.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <unistd.h>    /* geteuid */
  28. #include "types.h"
  29. #include "common.h"
  30. #include "intrface.h"
  31. #include "fnctdsk.h"
  32.  
  33. t_list_part *add_partition(t_param_disk *disk_car,t_list_part *list_part, const int debug)
  34. {
  35.   t_CHS start,end;
  36.   t_diskext *new_partition=partition_new();
  37.   int position=0;
  38.   start.cylinder=0;
  39.   start.head=0;
  40.   start.sector=1;
  41.   end.cylinder=disk_car->CHS.cylinder;
  42.   end.head=disk_car->CHS.head;
  43.   end.sector=disk_car->CHS.sector;
  44.   {
  45.     int done = FALSE;
  46.     while (done==FALSE) {
  47.       int command;
  48.       static struct MenuItem menuGeometry[]=
  49.       {
  50.     { 'c', "Cylinders",     "Change starting cylinder" },
  51.     { 'h', "Heads",     "Change starting head" },
  52.     { 's', "Sectors",     "Change starting sector" },
  53.     { 'C', "Cylinders",     "Change ending cylinder" },
  54.     { 'H', "Heads",     "Change ending head" },
  55.     { 'S', "Sectors",     "Change ending sector" },
  56.     { 'T' ,"Type",        "Change partition type"},
  57.     { 'd', "Done", "" },
  58.     { 0, NULL, NULL }
  59.       };
  60.       aff_copy(stdscr);
  61.       wmove(stdscr,4,0);
  62.       wdoprintf(stdscr,"%s",disk_car->description(disk_car));
  63.       new_partition->lba=CHS2LBA(disk_car,&start);
  64.       new_partition->part_size=CHS2LBA(disk_car,&end) - new_partition->lba + 1;
  65.       wmove(stdscr,10, 0);
  66.       wclrtoeol(stdscr);
  67.       aff_part(stdscr,AFF_PART_SHORT,disk_car,new_partition);
  68.       wmove(stdscr,COMMAND_LINE_Y, COMMAND_LINE_X);
  69.       wclrtoeol(stdscr);
  70.       wrefresh(stdscr);
  71.       command=wmenuSimple(stdscr,menuGeometry, position);
  72.       switch (command) {
  73.     case 'c':
  74.       start.cylinder=ask_number(start.cylinder,0,disk_car->CHS.cylinder,"Enter the starting cylinder ");
  75.       position=1;
  76.       break;
  77.     case 'h':
  78.       start.head=ask_number(start.head,0,disk_car->CHS.head,"Enter the starting head ");
  79.       position=2;
  80.       break;
  81.     case 's':
  82.       start.sector=ask_number(start.sector,1,disk_car->CHS.sector,"Enter the starting sector ");
  83.       position=3;
  84.       break;
  85.     case 'C':
  86.       end.cylinder=ask_number(end.cylinder,start.cylinder,disk_car->CHS.cylinder,"Enter the ending cylinder ");
  87.       position=4;
  88.       break;
  89.     case 'H':
  90.       end.head=ask_number(end.head,0,disk_car->CHS.head,"Enter the ending head ");
  91.       position=5;
  92.       break;
  93.     case 'S':
  94.       end.sector=ask_number(end.sector,1,disk_car->CHS.sector,"Enter the ending sector ");
  95.       position=6;
  96.       break;
  97.     case 'T':
  98.     case 't':
  99.       change_part_type(disk_car,new_partition);
  100.       position=7;
  101.       break;
  102.     case key_ESC:
  103.     case 'd':
  104.     case 'D':
  105.     case 'q':
  106.     case 'Q':
  107.       done = TRUE;
  108.       break;
  109.       }
  110.     }
  111.   }
  112.   if((CHS2LBA(disk_car,&end)>new_partition->lba)&&(new_partition->lba>0))
  113.   {
  114.     t_list_part *new_list_part=insert_new_partition(list_part, new_partition);
  115.     if(test_structure(list_part)==0)
  116.     { /* Determine if the partition can be Logical, Bootable or Primary */
  117.       if(can_be_ext(disk_car,new_partition)!=0)
  118.       {
  119.     new_partition->status=STATUS_LOG;
  120.     if(test_structure(new_list_part)==0)
  121.       return new_list_part;
  122.       }
  123.       new_partition->status=STATUS_PRIM_BOOT;
  124.       if(test_structure(new_list_part)==0)
  125.     return new_list_part;
  126.       new_partition->status=STATUS_PRIM;
  127.       if(test_structure(new_list_part)==0)
  128.     return new_list_part;
  129.       new_partition->status=STATUS_DELETED;
  130.     }
  131.     return new_list_part;
  132.   }
  133.   FREE(new_partition);
  134.   return list_part;
  135. }
  136.  
  137.